$(document).ready(function(){
	$.ajax({
		url: "/airbnb/getStoryType.do",
		async: false,
	   	type: "POST",
	   	error: function (){
	   		alert("ajax请求失败")
	   	},
	   	success: function(json){
	   		for(var i = 0; i < json.length; i++){
	   			$("#stotypeid").append("<option value='"+json[i].value+"'>"+json[i].text+"</option>")
	   		}
	   	}
	});
	
	
	$("#fabu").click(function(){
		var stotypeid=$("#stotypeid").val();
		var title=$("#title").val();
		var content=$("#content").val();
		$.ajax({
			url: "/airbnb/insertStory.do",
			async: false,
		   	type: "POST",
		   	data: {"stotypeid":stotypeid,"title":title,"content":content},
		   	error: function (){
		   		alert("ajax请求失败")
		   	},
		   	success: function(json){
		   		
		   		alert("发布成功")
		   		location.href="guanlistory.html";
		   	}
		});
	})
	
	layui.use('upload', function(){
	  	var $ = layui.jquery
	  	,upload = layui.upload;
	  
	  
	  //多图片上传
	  upload.render({
	    elem: '#test2'
	    ,url: '/airbnb/insertimg.do'
	    ,multiple: true
	    ,before: function(obj){
	      //预读本地文件示例，不支持ie8
	      obj.preview(function(index, file, result){
	        $('#demo2').append('<img src="'+ result +'" alt="'+ file.name +'" class="layui-upload-img">')
	      });
	    }
	    ,done: function(res){
	      //上传完毕
	      console.log(res)
	    }
	  });
	});
})
 